package com.imcode;

import java.io.*;

public class BufferedReaderWriterDemo {
    public static void main(String[] args) throws IOException {
        //1.创建一个字符缓冲输入流(读)
        BufferedReader br = new BufferedReader(new FileReader("file/1.txt"));
        // 创建一个字符缓冲输出流(写)
        BufferedWriter bw = new BufferedWriter(new FileWriter("file/5.txt"));
        //2.读取文件内容
        /*
        System.out.println(br.readLine());
        System.out.println(br.readLine());
        System.out.println(br.readLine());// 文件读取结束返回null*/

        String line = ""; // 存储每次循环读取到的一行内容
        while ((line=br.readLine()) != null) {
            //3.将每次读取到的一行数据写入到5.txt
            bw.write(line);
            bw.newLine();//换行
            //bw.flush();
        }
        //3.关闭流
        br.close();
        bw.close();
    }
}
